/**
 * Created by JasonChou on 16/6/6.
 */
import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);
export var router = new VueRouter();

router.map({
  '/': {
    name: 'test',
    component: function (resolve) {
      require.ensure(['./components/Test.vue'], function (require) {
        var component = require('./components/Test.vue');
        resolve(component);
      }, 'test');
    }
  },
  'mine': {
    name: 'mine',
    component: function (resolve) {
      require.ensure(['./components/Mine.vue'], function (require) {
        var component = require('./components/Mine.vue');
        resolve(component);
      }, 'mine');
    }
  },
  'user_setting': {
    name: 'userSetting',
    component: function (resolve) {
      require.ensure(['./components/UserSetting.vue'], function (require) {
        var component = require('./components/UserSetting.vue');
        resolve(component);
      }, 'userSetting');
    }
  },
  'user/:userId/:self_sector/:self_role/:self_v': {
    name: 'user',
    component: function (resolve) {
      require.ensure(['./components/User.vue'], function (require) {
        var component = require('./components/User.vue');
        resolve(component);
      }, 'user');
    }
  },

  'user/:userId': {
    name: 'user',
    component: function (resolve) {
      require.ensure(['./components/User.vue'], function (require) {
        var component = require('./components/User.vue');
        resolve(component);
      }, 'user');
    }
  }
});

router.redirect({
  '*': '/404'
});

router.beforeEach(function (transition) {
  if (window.scrollY > 0)
    //positionCache[transition.from.path] = window.scrollY;


  if (refreshCache[transition.to.name]) {
    transition.to.params.refresh = true;
    delete  refreshCache[transition.to.name];
  }

  console.log(transition);

  transition.next();
});

